home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 2: CDPD 1 / Almathera Ten on Ten - Disc 2: CDPD 1.iso / pd / 076-100 / 084 / ed / maksub.c < prev    next >
C/C++ Source or Header  |  1995-03-13  |  1KB  |  91 lines

  1. /*
  2.  * Copyright 1987 Brian Beattie Rights Reserved.
  3.  *
  4.  * Permission to copy and/or distribute granted under the
  5.  * following conditions:
  6.  *
  7.  * 1). No charge may be made other than resonable charges
  8.  *    for reproduction.
  9.  *
  10.  * 2). This notice must remain intact.
  11.  *
  12.  * 3). No further restrictions may be added.
  13.  *
  14.  */
  15. #include <stdio.h>
  16. #include "tools.h"
  17. #include "ed.h"
  18.  
  19. char    *
  20. maksub(sub, subsz)
  21. char    *sub;
  22. int    subsz;
  23. {
  24.     int    size;
  25.     char    delim, *cp;
  26.  
  27.     size = 0;
  28.     cp = sub;
  29.  
  30.     delim = *inptr++;
  31.     for(size = 0; *inptr != delim && *inptr != NL && size < subsz; size++)
  32.     {
  33.         if(*inptr == '&')
  34.         {
  35.             *cp++ = DITTO;
  36.             inptr++;
  37.         } else {
  38.             if(*inptr == ESCAPE)
  39.             {
  40.                 inptr++;
  41.                 if(*inptr < '0' || *inptr > '7')
  42.                     switch(toupper(*++inptr))
  43.                     {
  44.                     case NL:
  45.                         *cp++ == ESCAPE;
  46.                         break;
  47.                     case 'S':
  48.                         *cp++ = SP;
  49.                         inptr++;
  50.                         break;
  51.                     case 'N':
  52.                         *cp++ = NL;
  53.                         inptr++;
  54.                         break;
  55.                     case 'T':
  56.                         *cp++ = HT;
  57.                         inptr++;
  58.                         break;
  59.                     case 'B':
  60.                         *cp++ = BS;
  61.                         inptr++;
  62.                         break;
  63.                     case 'R':
  64.                         *cp++ = CR;
  65.                         inptr++;
  66.                         break;
  67.                     default:
  68.                         *cp++ = *inptr;
  69.                         inptr++;
  70.                         break;
  71.                     }
  72.                 else {
  73.                     *cp = 0;
  74.                     while(*inptr >= '0' && *inptr <= '7')
  75.                     {
  76.                         *cp = (*cp << 3)+(*inptr-'0');
  77.                         inptr++;
  78.                     }
  79.                     cp++;
  80.                 }
  81.             } else
  82.                 *cp++ = *inptr++;
  83.         }
  84.     }
  85.     if(size >= subsz)
  86.         return( NULL );
  87.  
  88.     *cp = EOS;
  89.     return( sub );
  90. }
  91.